package com.zeratul.common.satoken.enums;

import com.zeratul.common.core.exception.ServiceException;
import com.zeratul.common.satoken.codes.AuthResultCodes;
import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * 登录方式
 */
@Getter
@AllArgsConstructor
public enum LoginType {

    /**
     * 账号密码登录
     */
    PASSWORD("password"),

    /**
     * 手机验证码登录
     */
    SMS("sms"),

    /**
     * 邮箱验证码登录
     */
    EMAIL("email"),

    /**
     * 微信小程序登录
     */
    WECHAT_MP("wechat-mp");

    /**
     * 登录方式Code码
     */
    private final String code;

    /**
     * 根据code获取登录方式对象
     */
    public static LoginType getByCode(String code) {
        for (LoginType loginType : LoginType.values()) {
            if (!loginType.getCode().equals(code)) {
                continue;
            }
            return loginType;
        }
        throw new ServiceException(AuthResultCodes.NOT_FOUND_LOGIN_TYPE, "无效的登录方式：" + code);
    }
}
